﻿using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ZerAx.ObjectNotation
{
    public class ZonI32Array : Zon
    {
        public override ZonType Type => ZonType.I32Array;
        public readonly List<int> data;

        public ZonI32Array()
        {
            data = new();
        }

        public ZonI32Array(IEnumerable<int> values)
        {
            data = new(values);
        }

        public ZonI32Array(params int[] values) : this(values.AsEnumerable()) { }

        public override void Initialize(BinaryReader reader)
        {
            int count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                data.Add(reader.ReadInt32());
            }
        }

        public override void SerializeData(BinaryWriter writer)
        {
            writer.Write(data.Count);
            foreach (var i in data)
            {
                writer.Write(i);
            }
        }

        public override string ToString()
        {
            return $"i[{string.Join(',', data)}]";
        }
    }
}
